﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

using Microsoft.CustomTool;
using System.IO;
using System.Diagnostics;
using King.CSharp.Text;

namespace King.VisualStudioCustomTool {

    public class IgnoreThisException : Exception { }

    [Guid("BC35736B-BE8C-4226-B939-C2CC47ED585B")]
    public class KingCustomTool : BaseCodeGeneratorWithSite {

        protected override byte[] GenerateCode(string inputFileName, string inputFileContent) {
            var unit = new CSharpCompilationUnitSyntax { inputFileContent };

            using (var writer = new StreamWriter(inputFileName, false, Encoding.UTF8))
                writer.Write(unit.ToString());
            //GeneratorErrorCallback(true, 0, "A warning", 0, 0);
            //GeneratorErrorCallback(false, 0, "An error", 0, 0);

            // prevent single file generation by throwing an exception
            throw new IgnoreThisException();
        }
    }
}
